<?php

/**
 * This is the model class for table "{{apps}}".
 *
 * The followings are the available columns in table '{{apps}}':
 * @property integer $app_id
 * @property integer $admin_id
 * @property string $category_code
 * @property string $app_type
 * @property string $app_name
 * @property integer $download_count
 * @property string $icon_src
 * @property string $img
 * @property string $last_update
 * @property string $install_url
 * @property string $platform_type
 * @property double $original_price
 * @property double $price
 * @property integer $size
 * @property integer $score
 * @property string $corporation
 * @property string $summary
 * @property string $version
 * @property string $ctime
 * @property string $mtime
 * @property string $status
 */
class Apps extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Apps the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{apps}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('admin_id, category_code, app_name, download_count, icon_src, img, install_url, corporation, version, ctime', 'required'),
			array('admin_id, download_count, size, score', 'numerical', 'integerOnly'=>true),
			array('original_price, price', 'numerical'),
			array('category_code, corporation', 'length', 'max'=>60),
			array('app_type', 'length', 'max'=>4),
			array('app_name', 'length', 'max'=>100),
			array('icon_src, img, install_url', 'length', 'max'=>255),
			array('platform_type, status', 'length', 'max'=>7),
			array('version', 'length', 'max'=>20),
			array('summary, mtime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('app_id, admin_id, category_code, app_type, app_name, download_count, icon_src, img, last_update, install_url, platform_type, original_price, price, size, score, corporation, summary, version, ctime, mtime, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'app_id' => 'App',
			'admin_id' => 'Admin',
			'category_code' => 'Category Code',
			'app_type' => 'App Type',
			'app_name' => 'App Name',
			'download_count' => 'Download Count',
			'icon_src' => 'Icon Src',
			'img' => 'Img',
			'last_update' => 'Last Update',
			'install_url' => 'Install Url',
			'platform_type' => 'Platform Type',
			'original_price' => 'Original Price',
			'price' => 'Price',
			'size' => 'Size',
			'score' => 'Score',
			'corporation' => 'Corporation',
			'summary' => 'Summary',
			'version' => 'Version',
			'ctime' => 'Ctime',
			'mtime' => 'Mtime',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('app_id',$this->app_id);
		$criteria->compare('admin_id',$this->admin_id);
		$criteria->compare('category_code',$this->category_code,true);
		$criteria->compare('app_type',$this->app_type,true);
		$criteria->compare('app_name',$this->app_name,true);
		$criteria->compare('download_count',$this->download_count);
		$criteria->compare('icon_src',$this->icon_src,true);
		$criteria->compare('img',$this->img,true);
		$criteria->compare('last_update',$this->last_update,true);
		$criteria->compare('install_url',$this->install_url,true);
		$criteria->compare('platform_type',$this->platform_type,true);
		$criteria->compare('original_price',$this->original_price);
		$criteria->compare('price',$this->price);
		$criteria->compare('size',$this->size);
		$criteria->compare('score',$this->score);
		$criteria->compare('corporation',$this->corporation,true);
		$criteria->compare('summary',$this->summary,true);
		$criteria->compare('version',$this->version,true);
		$criteria->compare('ctime','>='.$this->ctime,true);
		$criteria->compare('mtime','<='.$this->mtime,true);
		$criteria->compare('status',$this->status,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}